var http = require("http");
var url = require("url");
var sys = require("sys");


///////////////////////////////////////////
exports.start = function start(route, handle) {
    function onRequest(request, respone) {
        //过滤掉对/favicon.ico的请求
        var pathname = url.parse(request.url).pathname;
        if (pathname === "/favicon.ico") {
            return;
        }

        //respone.writeHead(200, {"Content-Type":"text/plain"});
        //respone.write("Hello world");
        console.log("===========Request received===========");
        console.log("Request for " + pathname + " received.");
        /*var postData = "";
        request.setEncoding("utf-8");
        request.addListener("data", function (postDataChunk) {
            postData += postDataChunk;
            console.log("Received POST data chunk '" + postDataChunk + "'.");
        });

        request.addListener("end", function () {
            route(handle, pathname, respone, postData);
        });*/

        route(handle, pathname, request, respone);

        //respone.end();
    }

    http.createServer(onRequest).listen(8000);
    console.log("Server has started.");
}
